<?
include "loggedin.inc.php";
require('../includes/messages.inc.php');
require('../includes/config.inc.php');
require("header.php");
require('../includes/styles.inc.php');

if(isset($_POST[s1]))
{
	//get the original file name

	if(empty($_POST[LinkURL]) || empty($_POST[LinkName]))
	{
		echo "<center><br><font color=red size=2 face=verdana><b>All fields are required!</b></font></center>";
	}
	else
	{

		$q1 = "insert into PHPAUCTION_links set
							LinkName = '$_POST[LinkName]',
							LinkURL = '$_POST[LinkURL]'";

		mysql_query($q1) or die(mysql_error());
	}
}
if($_GET[action] == 'delete')
{
	$LinkID = $_GET[LinkID];
	$pass = $_GET[pass];
	$q2 = "delete from PHPAUCTION_links where LinkID = '$LinkID'";
	mysql_query($q2);
}

?>

<script>

function NewBanner() {

	if(document.f1.BannerFile.value=="")
	{
		alert('Select the banner file from your computer!');
		document.f1.BannerFile.focus();
		return false;
	}

	if(document.f1.BannerAlt.value=="")
	{
		alert('Enter the ALT text, please!');
		document.f1.BannerAlt.focus();
		return false;
	}

	if(document.f1.BannerURL.value=="" || document.f1.BannerURL.value.length < '11')
	{
		alert('Enter the URL, please!\n\nFormat: http://www.domain.com');
		document.f1.BannerURL.focus();
		document.f1.BannerURL.value="http://";
		return false;
	}

}

</script>

<form method=post action=links.php>
<input type=hidden name=pass value="<?=$pass?>">
  <table align=center width=450>
    <caption align=center>
    <font size=2 face=verdana color=black><b>Add a new Link</b></font>
    </caption>
    <tr>
      <td><font size=2 face=verdana color=black><b>Link Name:</b></font></td>
      <td><input name=LinkName type=text id="LinkName"></td>
    </tr>
    <tr>
      <td><font size=2 face=verdana color=black><b>Link URL:<b></font></td>
      <td><input name=LinkURL type=text id="LinkURL" value="http://"></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type=submit name=s1 value="Submit"></td>
    </tr>
  </table>
  </form>

<?

//get the banners
$q1 = "select * from PHPAUCTION_links";
$r1 = mysql_query($q1) or die(mysql_error());

if(mysql_num_rows($r1) == '0')
{
	exit();
}

while($a1 = mysql_fetch_array($r1))
{
	?>
			<center>
				<a class=Nav href="<?=$a1[LinkURL]?>"><?=$a1[LinkName]?></a><br>


				<a class=Nav href="EditLinks.php?LinkID=<?=$a1[LinkID]?>&pass=<?php echo($pass); ?>"><b>edit</b></a> |
				<a class=DNav href="links.php?LinkID=<?=$a1[LinkID]?>&pass=<?php echo($pass); ?>&action=delete"><b>delete</b></a>

				<br><br>
			</center>
	<?
}
?>


</table>

<?
include("footer.php");
?>